﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace INorQuit
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }



        protected void lg_Authenticate(object sender, AuthenticateEventArgs e)
        {
            var username = lg.UserName.Trim();
            var password = lg.Password.Trim();
            var sql = string.Format("select * from users where username='{0}'and password='{1}'", username, password);
            var dt = DbHelper.GetData(sql);

            if (dt.Rows.Count == 1) 
            {
                var row = dt.Rows[0];
                var isActived = (bool)row.ItemArray[3];
                var isDeleted = (bool)row.ItemArray[4];
                if (isDeleted) 
                {
                    //账号被删除
                    lb1Comment.Text = "账号被删除或注销，如有疑问，请询问客服";
                }
                else
                {
                    //没有被删除，继续判断是否启用
                    if (isActived)
                    {
                        //已启用，返回起始界面
                        Response.Redirect("default.aspx");
                    }
                    else
                    {
                        //账号停用
                        lb1Comment.Text = "该账户已停用，如有疑问，请询问客服";
                    }
                }
            }
            else
            {
                //验证失败，重试
                lb1Comment.Text = "账号或密码错误，请重试";
            }
        }
    }
}